using System;
using System.Collections.Generic;
using System.Text;
using HappySprite;
using HappySprite.Graphics;

namespace HappyInvaders
{
    class ExplosionVisual : Visual
    {
        int flip;

        ImageMap[] images = new ImageMap[2];

        public ExplosionVisual()
        {
            Item.RenderItem.Width = Constants.PlayerWidth;
            Item.RenderItem.Height = Constants.PlayerHeight;

            images[0] = new ImageMap(Constants.ExplosionTexture1);
            images[1] = new ImageMap(Constants.ExplosionTexture2);
        }

        internal override void OnAdd(View view)
        {
            Global.EventScheduler.Schedule(0.05f, FlipAnimation);
            Global.Audio.PlayToEnd(Constants.ExplosionCue);
        }

        internal override void OnRemove()
        {
            Global.EventScheduler.Cancel(FlipAnimation);
        }

        void FlipAnimation()
        {
            Global.EventScheduler.Schedule(0.05f, FlipAnimation);
            flip ^= 1;
            Item.RenderItem.ImageMap = images[flip];
        }
    }
}
